<template>
	<view>

		<view class="title_box">
			<view>{{details.title}}</view>
			<!-- <view>{{details.create_time}}</view> -->
		</view>

		<view class="u-content">
			<u-parse :html="details.contents"></u-parse>
		</view>
		
		
		<!--客服-->
		<!-- #ifdef APP-PLUS || H5 -->
		<view class="kefu_Box" @click="callservice()">
			<image class="kefu_icon" :src="BestImgUrl+'kefu_icon.png'"></image>
		</view>
		<!-- #endif -->
		
		<!-- #ifdef MP-WEIXIN -->
		<view class="kefu_Box">
			<button type="default" open-type="contact">
				<image class="kefu_icon" :src="BestImgUrl+'kefu_icon.png'"></image>
			</button>
		</view>
		<!-- #endif -->


	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				gid: '',
				details: {},
				BestImgUrl: app.globalData.imgurlBwc,
			}
		},
		onLoad(options) {
			let that = this
			let token = uni.getStorageSync('token')
			
			this.gid = options.id
			this.getDetails();
			
			// #ifdef MP-WEIXIN
			console.log('二维码信息', options)
			//绑定推荐人-小程序端
			if (JSON.stringify(options) != '{}') {
				let pdi = {
					parent_id: options.scene,
					reseller_id: {
						reseller_id: uni.getStorageSync('reseller_id') || ''
					}
				}
				app.globalData.bindSaveParentId(pdi);
			} else {
				//options为空
			}
			
			
			if (!token) {
				uni.login({
					provider: 'weixin',
					success: function(login_res) {
						that.$api.wxminiappLogon({
							code: login_res.code,
							avatar: that.$store.state.baseUrl + '/public/uploads/h5/me/Group-33475.png', //	是	string	用户头像
							nickname: '领食惠探店用户',
							username: '',
							appid: uni.getStorageSync('miniProgramAppId')
						}).then(res => {
							//console.log('微信小程序登录', res)
							uni.setStorageSync('token', res.data.result.token)
							setTimeout(() => {
								that.$api.GetuserInfo({
									
								}).then(res => {
									uni.setStorageSync('userinfo', res.data.result)
								}).catch(err => {
									
								})
							}, 500);
						}).catch(err => {})
					},
					fail: function(err) {}
				});
			} else {
				
			}
			// #endif
			
		},
		methods: {
			
			onShareAppMessage() {
				let that = this
				let myid = uni.getStorageSync('userinfo').id
				
				return {
				  title: that.details.title,
				  path: '/subpackageC/pages/rulepage/noticDetails/noticDetails?id=' + that.gid + '&parent_id=' + myid,
				  imageUrl: that.BestImgUrl + 'yiyuanchiwaimai.png',
				  type: 0,
				  success: (res) => {
				    //console.log("转发成功", res);
				  },
				  fail: (res) => {
				    //console.log("转发失败", res);
				  } 
				}
			},
			onShareTimeline() {
				let that = this
				let myid = uni.getStorageSync('userinfo').id
				
				return {
				  title: that.details.title,
				  query: '/subpackageC/pages/rulepage/noticDetails/noticDetails?id=' + that.gid + '&parent_id=' + myid,
				  imageUrl: that.BestImgUrl + 'yiyuanchiwaimai.png',
				  success: (res) => {
				    //console.log("转发成功", res);
				  },
				  fail: (res) => {
				    //console.log("转发失败", res);
				  } 
				}
			},
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			getDetails(){
				let that = this
				that.$api.getBzZxinListDetails({
					id: that.gid
				}).then(res => {
					console.log(res.data.result)
					that.details = res.data.result
					uni.setNavigationBarTitle({
						title: res.data.result.title
					})
				}).catch(err => {
					uni.showToast({
						title: err.data.msg,
						icon: 'none',
						duration: 2000
					});
				})
			},
			//拉起客服
			callservice() {
				let data = uni.getStorageSync('customerServiceData')
				// #ifdef H5
				window.location.href = data.h5.url
				// #endif
				
				// #ifdef APP-PLUS
				let appurl = data.app.url
				uni.navigateTo({
					url: '/pages/Webview/Webview?url=' + encodeURIComponent(JSON.stringify(appurl))
				})
				// #endif
			
			},
			// 小程序跳转企业客服
			toCustomerServicePages: function() {
				try {
					let data = uni.getStorageSync('customerServiceErWeima')
					console.log('客服链接',data)
					
					wx.openCustomerServiceChat({
						extInfo: {
							url: data.path //客服ID
						},
						corpId: data.appid, //企业微信ID
						success(res) {}
					})
				} catch (error) {
					showToast("请更新至微信最新版本")
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.u-content {
		padding: 30rpx;
		color: #666666;
	}

	.title_box {
		text-align: left;
		width: 90%;
		margin: 26rpx auto;
		border-bottom: 1px solid #E4E4E4;

		view:nth-child(1) {
			font-size: 36rpx;
			font-weight: bold;
			margin-bottom: 36rpx;
		}

		view:nth-child(2) {
			color: #999;
		}
	}
</style>